home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_Tix.idb / usr / freeware / lib / tix4.1 / Grid.tcl.z / Grid.tcl
Encoding:
Text File  |  1999-01-26  |  20.7 KB  |  1,114 lines

  1. # Grid.tcl --
  2. #
  3. #     This file defines the default bindings for Tix Grid widgets.
  4. #
  5. # Copyright (c) 1996, Expert Interface Technologies
  6. #
  7. # See the file "license.terms" for information on usage and redistribution
  8. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  9. #
  10.  
  11.  
  12.  
  13. #--------------------------------------------------------------------------
  14. # tkPriv elements used in this file:
  15. #
  16. # afterId -        Token returned by "after" for autoscanning.
  17. # fakeRelease -        Cancel the ButtonRelease-1 after the user double click
  18. #--------------------------------------------------------------------------
  19. #
  20. proc tixGridBind {} {
  21.     tixBind TixGrid <ButtonPress-1> {
  22.     tixGrid:Button-1 %W %x %y
  23.     }
  24.     tixBind TixGrid <Shift-ButtonPress-1> {
  25.     tixGrid:Shift-Button-1 %W %x %y
  26.     }
  27.     tixBind TixGrid <Control-ButtonPress-1> {
  28.     tixGrid:Control-Button-1 %W %x %y
  29.     }
  30.     tixBind TixGrid <ButtonRelease-1> {
  31.     tixGrid:ButtonRelease-1 %W %x %y
  32.     }
  33.     tixBind TixGrid <Double-ButtonPress-1> {
  34.     tixGrid:Double-1 %W  %x %y
  35.     }
  36.     tixBind TixGrid <B1-Motion> {
  37.     set tkPriv(x) %x 
  38.     set tkPriv(y) %y
  39.     set tkPriv(X) %X
  40.     set tkPriv(Y) %Y
  41.  
  42.     tixGrid:B1-Motion %W %x %y
  43.     }
  44.     tixBind TixGrid <Control-B1-Motion> {
  45.     set tkPriv(x) %x 
  46.     set tkPriv(y) %y
  47.     set tkPriv(X) %X
  48.     set tkPriv(Y) %Y
  49.  
  50.     tixGrid:Control-B1-Motion %W %x %y
  51.     }
  52.     tixBind TixGrid <B1-Leave> {
  53.     set tkPriv(x) %x 
  54.     set tkPriv(y) %y
  55.     set tkPriv(X) %X
  56.     set tkPriv(Y) %Y
  57.  
  58.     tixGrid:B1-Leave %W
  59.     }
  60.     tixBind TixGrid <B1-Enter> {
  61.     tixGrid:B1-Enter %W %x %y
  62.     }
  63.     tixBind TixGrid <Control-B1-Leave> {
  64.     set tkPriv(x) %x 
  65.     set tkPriv(y) %y
  66.     set tkPriv(X) %X
  67.     set tkPriv(Y) %Y
  68.  
  69.     tixGrid:Control-B1-Leave %W
  70.     }
  71.     tixBind TixGrid <Control-B1-Enter> {
  72.     tixGrid:Control-B1-Enter %W %x %y
  73.     }
  74.  
  75.     # Keyboard bindings
  76.     #
  77.     tixBind TixGrid <Up> {
  78.     tixGrid:DirKey %W up
  79.     }
  80.     tixBind TixGrid <Down> {
  81.     tixGrid:DirKey %W down
  82.     }
  83.     tixBind TixGrid <Left> {
  84.     tixGrid:DirKey %W left
  85.     }
  86.     tixBind TixGrid <Right> {
  87.     tixGrid:DirKey %W right
  88.     }
  89.     tixBind TixGrid <Prior> {
  90.     %W yview scroll -1 pages
  91.     }
  92.     tixBind TixGrid <Next> {
  93.     %W yview scroll 1 pages
  94.     }
  95.     tixBind TixGrid <Return> {
  96.     tixGrid:Return %W 
  97.     }
  98.     tixBind TixGrid <space> {
  99.     tixGrid:Space %W 
  100.     }
  101. }
  102.  
  103. #----------------------------------------------------------------------
  104. #
  105. #
  106. #             Mouse bindings
  107. #
  108. #
  109. #----------------------------------------------------------------------
  110.  
  111. proc tixGrid:Button-1 {w x y} {
  112.     if {[$w cget -state] == "disabled"} {
  113.     return
  114.     }
  115.     tixGrid:SetFocus $w
  116.  
  117.     case [tixGrid:GetState $w] {
  118.     {0} {
  119.         tixGrid:GoState 1 $w $x $y
  120.            }
  121.     }
  122. }
  123.  
  124. proc tixGrid:Shift-Button-1 {w x y} {
  125.     if {[$w cget -state] == "disabled"} {
  126.     return
  127.     }
  128.     tixGrid:SetFocus $w
  129.  
  130.     case [tixGrid:GetState $w] {
  131.     }
  132. }
  133.  
  134. proc tixGrid:Control-Button-1 {w x y} {
  135.     if {[$w cget -state] == "disabled"} {
  136.     return
  137.     }
  138.     tixGrid:SetFocus $w
  139.  
  140.     case [tixGrid:GetState $w] {
  141.     {s0} {
  142.         tixGrid:GoState s1 $w $x $y
  143.            }
  144.     {b0} {
  145.         tixGrid:GoState b1 $w $x $y
  146.            }
  147.     {m0} {
  148.         tixGrid:GoState m1 $w $x $y
  149.            }
  150.     {e0} {
  151.         tixGrid:GoState e10 $w $x $y
  152.            }
  153.     }
  154. }
  155.  
  156. proc tixGrid:ButtonRelease-1 {w x y} {
  157.     case [tixGrid:GetState $w] {
  158.     {2} {
  159.         tixGrid:GoState 5 $w $x $y
  160.     }
  161.     {4} {
  162.         tixGrid:GoState 3 $w $x $y
  163.     }
  164.     }
  165. }
  166.  
  167. proc tixGrid:B1-Motion {w x y} {
  168.     case [tixGrid:GetState $w] {
  169.     {2 4} {
  170.         tixGrid:GoState 4 $w $x $y
  171.     }
  172.     }
  173. }
  174.  
  175. proc tixGrid:Control-B1-Motion {w x y} {
  176.     case [tixGrid:GetState $w] {
  177.     {s2 s4} {
  178.         tixGrid:GoState s4 $w $x $y 
  179.     }
  180.     {b2 b4} {
  181.         tixGrid:GoState b4 $w $x $y 
  182.     }
  183.     {m2 m5} {
  184.         tixGrid:GoState m4 $w $x $y 
  185.     }
  186.     }
  187. }
  188.  
  189. proc tixGrid:Double-1 {w x y} {
  190.     case [tixGrid:GetState $w] {
  191.     {s0} {
  192.         tixGrid:GoState s7 $w $x $y
  193.     }
  194.     {b0} {
  195.         tixGrid:GoState b7 $w $x $y
  196.     }
  197.     }
  198. }
  199.  
  200. proc tixGrid:B1-Leave {w} {
  201.     case [tixGrid:GetState $w] {
  202.     {s2 s4} {
  203.         tixGrid:GoState s5 $w
  204.     }
  205.     {b2 b4} {
  206.         tixGrid:GoState b5 $w
  207.     }
  208.     {m2 m5} {
  209.         tixGrid:GoState m8 $w
  210.     }
  211.     {e2 e5} {
  212.         tixGrid:GoState e8 $w
  213.     }
  214.     }
  215. }
  216.  
  217. proc tixGrid:B1-Enter {w x y} {
  218.     case [tixGrid:GetState $w] {
  219.     {s5 s6} {
  220.         tixGrid:GoState s4 $w $x $y
  221.     }
  222.     {b5 b6} {
  223.         tixGrid:GoState b4 $w $x $y
  224.     }
  225.     {m8 m9} {
  226.         tixGrid:GoState m4 $w $x $y
  227.     }
  228.     {e8 e9} {
  229.         tixGrid:GoState e4 $w $x $y
  230.     }
  231.     }
  232. }
  233.  
  234. proc tixGrid:Control-B1-Leave {w} {
  235.     case [tixGrid:GetState $w] {
  236.     {s2 s4} {
  237.         tixGrid:GoState s5 $w
  238.     }
  239.     {b2 b4} {
  240.         tixGrid:GoState b5 $w
  241.     }
  242.     {m2 m5} {
  243.         tixGrid:GoState m8 $w
  244.     }
  245.     }
  246. }
  247.  
  248. proc tixGrid:Control-B1-Enter {w x y} {
  249.     case [tixGrid:GetState $w] {
  250.     {s5 s6} {
  251.         tixGrid:GoState s4 $w $x $y
  252.     }
  253.     {b5 b6} {
  254.         tixGrid:GoState b4 $w $x $y
  255.     }
  256.     {m8 m9} {
  257.         tixGrid:GoState m4 $w $x $y
  258.     }
  259.     }
  260. }
  261.  
  262. proc tixGrid:AutoScan {w} {
  263.     case [tixGrid:GetState $w] {
  264.     {s5 s6} {
  265.         tixGrid:GoState s6 $w
  266.     }
  267.     {b5 b6} {
  268.         tixGrid:GoState b6 $w
  269.     }
  270.     {m8 m9} {
  271.         tixGrid:GoState m9 $w
  272.     }
  273.     {e8 e9} {
  274.         tixGrid:GoState e9 $w
  275.     }
  276.     }
  277. }
  278.  
  279. #----------------------------------------------------------------------
  280. #
  281. #
  282. #             Key bindings
  283. #
  284. #
  285. #----------------------------------------------------------------------
  286. proc tixGrid:DirKey {w key} {
  287.     if {[$w cget -state] == "disabled"} {
  288.     return
  289.     }
  290.     case [tixGrid:GetState $w] {
  291.     {s0} {
  292.         tixGrid:GoState s8 $w $key
  293.            }
  294.     {b0} {
  295.         tixGrid:GoState b8 $w $key
  296.            }
  297.     }
  298. }
  299.  
  300. proc tixGrid:Return {w} {
  301.     if {[$w cget -state] == "disabled"} {
  302.     return
  303.     }
  304.     case [tixGrid:GetState $w] {
  305.     {s0} {
  306.         tixGrid:GoState s9 $w
  307.            }
  308.     {b0} {
  309.         tixGrid:GoState b9 $w
  310.            }
  311.     }
  312. }
  313.  
  314. proc tixGrid:Space {w} {
  315.     if {[$w cget -state] == "disabled"} {
  316.     return
  317.     }
  318.     case [tixGrid:GetState $w] {
  319.     {s0} {
  320.         tixGrid:GoState s10 $w
  321.            }
  322.      {b0} {
  323.         tixGrid:GoState b10 $w
  324.            }
  325.    }
  326. }
  327.  
  328. #----------------------------------------------------------------------
  329. #
  330. #            STATE MANIPULATION
  331. #
  332. #
  333. #----------------------------------------------------------------------
  334. proc tixGrid:GetState {w} {
  335.     global $w:priv:state
  336.  
  337.     if {![info exists $w:priv:state]} {
  338.     set $w:priv:state 0
  339.     }
  340.     return [set $w:priv:state]
  341. }
  342.  
  343. proc tixGrid:SetState {w n} {
  344.     global $w:priv:state
  345.  
  346.     set $w:priv:state $n
  347. }
  348.  
  349. proc tixGrid:GoState {n w args} {
  350.  
  351. #   puts "going from [tixGrid:GetState $w] --> $n"
  352.  
  353.     tixGrid:SetState $w $n
  354.     eval tixGrid:GoState-$n $w $args
  355. }
  356.  
  357. #----------------------------------------------------------------------
  358. #           SELECTION ROUTINES
  359. #----------------------------------------------------------------------
  360. proc tixGrid:SelectSingle {w ent} {
  361.     $w selection set [lindex $ent 0] [lindex $ent 1]
  362.     tixGrid:CallBrowseCmd $w $ent
  363. }
  364.  
  365. #----------------------------------------------------------------------
  366. #    SINGLE SELECTION
  367. #----------------------------------------------------------------------
  368. proc tixGrid:GoState-0 {w} {
  369.     set list $w:_list
  370.     global $list
  371.  
  372.     if [info exists $list] {
  373.     foreach cmd [set $list] {
  374.         uplevel #0 $cmd
  375.     }
  376.     if [info exists $list] {
  377.         unset $list
  378.     }
  379.     }
  380. }
  381.  
  382. proc tixGrid:GoState-1 {w x y} {
  383.     set ent [$w nearest $x $y]
  384.     if {$ent != ""} {
  385.     tixGrid:SetAnchor $w $ent
  386.     }
  387.     tixGrid:CheckEdit $w
  388.     $w selection clear 0 0 max max
  389.  
  390.     if [string compare [$w cget -selectmode] single] {
  391.     tixGrid:SelectSingle $w $ent
  392.     }
  393.     tixGrid:GoState 2 $w
  394. }
  395.  
  396. proc tixGrid:GoState-2 {w} {
  397. }
  398.  
  399. proc tixGrid:GoState-3 {w x y} {
  400.     set ent [$w nearest $x $y]
  401.  
  402.     if {$ent != ""} {
  403.     tixGrid:SelectSingle $w $ent
  404.     }
  405.     tixGrid:GoState 0 $w
  406. }
  407.  
  408. proc tixGrid:GoState-5 {w x y} {
  409.     set ent [$w nearest $x $y]
  410.  
  411.     if {$ent != ""} {
  412.     tixGrid:SelectSingle $w $ent
  413.     tixGrid:SetEdit $w $ent
  414.     }
  415.     tixGrid:GoState 0 $w
  416. }
  417.  
  418.  
  419. proc tixGrid:GoState-4 {w x y} {
  420.     set ent [$w nearest $x $y]
  421.  
  422.     case [$w cget -selectmode] {
  423.     single {
  424.         tixGrid:SetAnchor $w $ent
  425.     }
  426.     browse {
  427.         tixGrid:SetAnchor $w $ent
  428.         $w selection clear 0 0 max max
  429.         tixGrid:SelectSingle $w $ent
  430.     }
  431.     {multiple extended} {
  432.         set anchor [$w anchor get]
  433.         $w selection adjust [lindex $anchor 0] [lindex $anchor 1] \
  434.         [lindex $ent 0] [lindex $ent 1]
  435.     }
  436.     }
  437. }
  438.  
  439. proc tixGrid:GoState-s5 {w} {
  440.     tixGrid:StartScan $w
  441. }
  442.  
  443. proc tixGrid:GoState-s6 {w} {
  444.     global tkPriv
  445.  
  446.     tixGrid:DoScan $w
  447. }
  448.  
  449. proc tixGrid:GoState-s7 {w x y} {
  450.     set ent [$w nearest $x $y]
  451.  
  452.     if {$ent != ""} {
  453.     $w selection clear
  454.     $w selection set $ent
  455.     tixGrid:CallCommand $w $ent
  456.     }
  457.     tixGrid:GoState s0 $w
  458. }
  459.  
  460. proc tixGrid:GoState-s8 {w key} {
  461.     set anchor [$w info anchor]
  462.  
  463.     if {$anchor == ""} {
  464.     set anchor 0
  465.     } else {
  466.     set anchor [$w info $key $anchor]
  467.     }
  468.  
  469.     $w anchor set $anchor
  470.     $w see $anchor
  471.     tixGrid:GoState s0 $w
  472. }
  473.  
  474. proc tixGrid:GoState-s9 {w} {
  475.     set anchor [$w info anchor]
  476.  
  477.     if {$anchor == ""} {
  478.     set anchor 0
  479.     $w anchor set $anchor
  480.     $w see $anchor
  481.     }
  482.  
  483.     if {[$w info anchor] != ""} {
  484.     # ! may not have any elements
  485.     #
  486.     tixGrid:CallCommand $w [$w info anchor]
  487.     $w selection clear 
  488.     $w selection set $anchor
  489.     }
  490.  
  491.     tixGrid:GoState s0 $w
  492. }
  493.  
  494. proc tixGrid:GoState-s10 {w} {
  495.     set anchor [$w info anchor]
  496.  
  497.     if {$anchor == ""} {
  498.     set anchor 0
  499.     $w anchor set $anchor
  500.     $w see $anchor
  501.     }
  502.  
  503.     if {[$w info anchor] != ""} {
  504.     # ! may not have any elements
  505.     #
  506.     tixGrid:CallBrowseCmd $w [$w info anchor]
  507.     $w selection clear 
  508.     $w selection set $anchor
  509.     }
  510.  
  511.     tixGrid:GoState s0 $w
  512. }
  513.  
  514. #----------------------------------------------------------------------
  515. #    BROWSE SELECTION
  516. #----------------------------------------------------------------------
  517. proc tixGrid:GoState-b0 {w} {
  518. }
  519.  
  520. proc tixGrid:GoState-b1 {w x y} {
  521.     set ent [$w nearest $x $y]
  522.     if {$ent != ""} {
  523.     $w anchor set $ent
  524.     $w selection clear
  525.     $w selection set $ent
  526.     tixGrid:CallBrowseCmd $w $ent
  527.     }
  528.     tixGrid:GoState b2 $w
  529. }
  530.  
  531. proc tixGrid:GoState-b2 {w} {
  532. }
  533.  
  534. proc tixGrid:GoState-b3 {w} {
  535.     set ent [$w info anchor]
  536.     if {$ent != ""} {
  537.     $w selection clear
  538.     $w selection set $ent
  539.     tixGrid:CallBrowseCmd $w $ent
  540.     }
  541.     tixGrid:GoState b0 $w
  542. }
  543.  
  544. proc tixGrid:GoState-b4 {w x y} {
  545.     set ent [$w nearest $x $y]
  546.     if {$ent != ""} {
  547.     $w anchor set $ent
  548.     $w selection clear
  549.     $w selection set $ent
  550.     tixGrid:CallBrowseCmd $w $ent
  551.     }
  552. }
  553.  
  554. proc tixGrid:GoState-b5 {w} {
  555.     tixGrid:StartScan $w
  556. }
  557.  
  558. proc tixGrid:GoState-b6 {w} {
  559.     global tkPriv
  560.  
  561.     tixGrid:DoScan $w
  562. }
  563.  
  564. proc tixGrid:GoState-b7 {w x y} {
  565.     set ent [$w nearest $x $y]
  566.  
  567.     if {$ent != ""} {
  568.     $w selection clear
  569.     $w selection set $ent
  570.     tixGrid:CallCommand $w $ent
  571.     }
  572.     tixGrid:GoState b0 $w
  573. }
  574.  
  575. proc tixGrid:GoState-b8 {w key} {
  576.     set anchor [$w info anchor]
  577.  
  578.     if {$anchor == ""} {
  579.     set anchor 0
  580.     } else {
  581.     set anchor [$w info $key $anchor]
  582.     }
  583.  
  584.     $w anchor set $anchor
  585.     $w selection clear
  586.     $w selection set $anchor
  587.     $w see $anchor
  588.  
  589.     tixGrid:CallBrowseCmd $w $anchor
  590.     tixGrid:GoState b0 $w
  591. }
  592.  
  593. proc tixGrid:GoState-b9 {w} {
  594.     set anchor [$w info anchor]
  595.  
  596.     if {$anchor == ""} {
  597.     set anchor 0
  598.     $w anchor set $anchor
  599.     $w see $anchor
  600.     }
  601.  
  602.     if {[$w info anchor] != ""} {
  603.     # ! may not have any elements
  604.     #
  605.     tixGrid:CallCommand $w [$w info anchor]
  606.     $w selection clear 
  607.     $w selection set $anchor
  608.     }
  609.  
  610.     tixGrid:GoState b0 $w
  611. }
  612.  
  613. proc tixGrid:GoState-b10 {w} {
  614.     set anchor [$w info anchor]
  615.  
  616.     if {$anchor == ""} {
  617.     set anchor 0
  618.     $w anchor set $anchor
  619.     $w see $anchor
  620.     }
  621.  
  622.     if {[$w info anchor] != ""} {
  623.     # ! may not have any elements
  624.     #
  625.     tixGrid:CallBrowseCmd $w [$w info anchor]
  626.     $w selection clear 
  627.     $w selection set $anchor
  628.     }
  629.  
  630.     tixGrid:GoState b0 $w
  631. }
  632.  
  633. #----------------------------------------------------------------------
  634. #    MULTIPLE SELECTION
  635. #----------------------------------------------------------------------
  636. proc tixGrid:GoState-m0 {w} {
  637. }
  638.  
  639. proc tixGrid:GoState-m1 {w x y} {
  640.     set ent [$w nearest $x $y]
  641.     if {$ent != ""} {
  642.     $w anchor set $ent
  643.     $w selection clear
  644.     $w selection set $ent
  645.     tixGrid:CallBrowseCmd $w $ent
  646.     }
  647.     tixGrid:GoState m2 $w
  648. }
  649.  
  650. proc tixGrid:GoState-m2 {w} {
  651. }
  652.  
  653. proc tixGrid:GoState-m3 {w} {
  654.     set ent [$w info anchor]
  655.     if {$ent != ""} {
  656.     tixGrid:CallBrowseCmd $w $ent
  657.     }
  658.     tixGrid:GoState m0 $w
  659. }
  660.  
  661. proc tixGrid:GoState-m4 {w x y} {
  662.     set from [$w info anchor]
  663.     set to   [$w nearest $x $y]
  664.     if {$to != ""} {
  665.     $w selection clear
  666.     $w selection set $from $to
  667.     tixGrid:CallBrowseCmd $w $to
  668.     }
  669.     tixGrid:GoState m5 $w
  670. }
  671.  
  672. proc tixGrid:GoState-m5 {w} {
  673. }
  674.  
  675. proc tixGrid:GoState-m6 {w x y} {
  676.     set ent [$w nearest $x $y]
  677.     if {$ent != ""} {
  678.     tixGrid:CallBrowseCmd $w $ent
  679.     }
  680.     tixGrid:GoState m0 $w  
  681. }
  682.  
  683. proc tixGrid:GoState-m7 {w x y} {
  684.     set from [$w info anchor]
  685.     set to   [$w nearest $x $y]
  686.     if {$from == ""} {
  687.     set from $to
  688.     $w anchor set $from
  689.     }
  690.     if {$to != ""} {
  691.     $w selection clear
  692.     $w selection set $from $to
  693.     tixGrid:CallBrowseCmd $w $to
  694.     }
  695.     tixGrid:GoState m5 $w
  696. }
  697.  
  698.  
  699. proc tixGrid:GoState-m8 {w} {
  700.     tixGrid:StartScan $w
  701. }
  702.  
  703. proc tixGrid:GoState-m9 {w} {
  704.     tixGrid:DoScan $w
  705. }
  706.  
  707. proc tixGrid:GoState-xm7 {w x y} {
  708.     set ent [$w nearest $x $y]
  709.  
  710.     if {$ent != ""} {
  711.     $w selection clear
  712.     $w selection set $ent
  713.     tixGrid:CallCommand $w $ent
  714.     }
  715.     tixGrid:GoState m0 $w
  716. }
  717.  
  718. #----------------------------------------------------------------------
  719. #    EXTENDED SELECTION
  720. #----------------------------------------------------------------------
  721. proc tixGrid:GoState-e0 {w} {
  722. }
  723.  
  724. proc tixGrid:GoState-e1 {w x y} {
  725.     set ent [$w nearest $x $y]
  726.     if {$ent != ""} {
  727.     $w anchor set $ent
  728.     $w selection clear
  729.     $w selection set $ent
  730.     tixGrid:CallBrowseCmd $w $ent
  731.     }
  732.     tixGrid:GoState e2 $w
  733. }
  734.  
  735. proc tixGrid:GoState-e2 {w} {
  736. }
  737.  
  738. proc tixGrid:GoState-e3 {w} {
  739.     set ent [$w info anchor]
  740.     if {$ent != ""} {
  741.     tixGrid:CallBrowseCmd $w $ent
  742.     }
  743.     tixGrid:GoState e0 $w
  744. }
  745.  
  746. proc tixGrid:GoState-e4 {w x y} {
  747.     set from [$w info anchor]
  748.     set to   [$w nearest $x $y]
  749.     if {$to != ""} {
  750.     $w selection clear
  751.     $w selection set $from $to
  752.     tixGrid:CallBrowseCmd $w $to
  753.     }
  754.     tixGrid:GoState e5 $w
  755. }
  756.  
  757. proc tixGrid:GoState-e5 {w} {
  758. }
  759.  
  760. proc tixGrid:GoState-e6 {w x y} {
  761.     set ent [$w nearest $x $y]
  762.     if {$ent != ""} {
  763.     tixGrid:CallBrowseCmd $w $ent
  764.     }
  765.     tixGrid:GoState e0 $w  
  766. }
  767.  
  768. proc tixGrid:GoState-e7 {w x y} {
  769.     set from [$w info anchor]
  770.     set to   [$w nearest $x $y]
  771.     if {$from == ""} {
  772.     set from $to
  773.     $w anchor set $from
  774.     }
  775.     if {$to != ""} {
  776.     $w selection clear
  777.     $w selection set $from $to
  778.     tixGrid:CallBrowseCmd $w $to
  779.     }
  780.     tixGrid:GoState e5 $w
  781. }
  782.  
  783.  
  784. proc tixGrid:GoState-e8 {w} {
  785.     tixGrid:StartScan $w
  786. }
  787.  
  788. proc tixGrid:GoState-e9 {w} {
  789.     tixGrid:DoScan $w
  790. }
  791.  
  792. proc tixGrid:GoState-e10 {w x y} {
  793.     set ent [$w nearest $x $y]
  794.     if {$ent != ""} {
  795.     if {[$w info anchor] == ""} {
  796.         $w anchor set $ent
  797.     }
  798.     if [$w selection includes $ent] {
  799.         $w selection clear $ent
  800.     } else {
  801.         $w selection set $ent
  802.     }
  803.     tixGrid:CallBrowseCmd $w $ent
  804.     }
  805.     tixGrid:GoState e2 $w
  806. }
  807.  
  808. proc tixGrid:GoState-xm7 {w x y} {
  809.     set ent [$w nearest $x $y]
  810.  
  811.     if {$ent != ""} {
  812.     $w selection clear
  813.     $w selection set $ent
  814.     tixGrid:CallCommand $w $ent
  815.     }
  816.     tixGrid:GoState e0 $w
  817. }
  818.  
  819. #----------------------------------------------------------------------
  820. #    HODGE PODGE
  821. #----------------------------------------------------------------------
  822.  
  823. proc tixGrid:GoState-12 {w x y} {
  824.     tkCancelRepeat
  825.     tixGrid:GoState 5 $w $x $y 
  826. }
  827.  
  828. proc tixGrid:GoState-13 {w ent oldEnt} {
  829.     global tkPriv
  830.     set tkPriv(tix,indicator) $ent
  831.     set tkPriv(tix,oldEnt)    $oldEnt
  832.     tixGrid:IndicatorCmd $w <Arm> $ent
  833. }
  834.  
  835. proc tixGrid:GoState-14 {w x y} {
  836.     global tkPriv
  837.  
  838.     if [tixGrid:InsideArmedIndicator $w $x $y] {
  839.     $w anchor set $tkPriv(tix,indicator)
  840.     $w select clear
  841.     $w select set $tkPriv(tix,indicator)
  842.     tixGrid:IndicatorCmd $w <Activate> $tkPriv(tix,indicator)
  843.     } else {
  844.     tixGrid:IndicatorCmd $w <Disarm>   $tkPriv(tix,indicator)
  845.     }
  846.  
  847.     unset tkPriv(tix,indicator)
  848.     tixGrid:GoState 0 $w
  849. }
  850.  
  851. proc tixGrid:GoState-16 {w ent} {
  852.     if {$ent == ""} {
  853.     return
  854.     }
  855.     if {[$w cget -selectmode] != "single"} {
  856.     tixGrid:Select $w $ent
  857.     tixGrid:Browse $w $ent
  858.     }
  859. }
  860.  
  861. proc tixGrid:GoState-18 {w} {
  862.     global tkPriv
  863.     tkCancelRepeat
  864.     tixGrid:GoState 6 $w $tkPriv(x) $tkPriv(y) 
  865. }
  866.  
  867. proc tixGrid:GoState-20 {w x y} {
  868.     global tkPriv
  869.  
  870.     if {![tixGrid:InsideArmedIndicator $w $x $y]} {
  871.     tixGrid:GoState 21 $w $x $y
  872.     } else {
  873.     tixGrid:IndicatorCmd $w <Arm> $tkPriv(tix,indicator)
  874.     }
  875. }
  876.  
  877. proc tixGrid:GoState-21 {w x y} {
  878.     global tkPriv
  879.  
  880.     if {[tixGrid:InsideArmedIndicator $w $x $y]} {
  881.     tixGrid:GoState 20 $w $x $y
  882.     } else {
  883.     tixGrid:IndicatorCmd $w <Disarm> $tkPriv(tix,indicator)
  884.     }
  885. }
  886.  
  887. proc tixGrid:GoState-22 {w} {
  888.     global tkPriv
  889.  
  890.     if {$tkPriv(tix,oldEnt) != ""} {
  891.     $w anchor set $tkPriv(tix,oldEnt)
  892.     } else {
  893.     $w anchor clear
  894.     }
  895.     tixGrid:GoState 0 $w
  896. }
  897.  
  898.  
  899. #----------------------------------------------------------------------
  900. #            callback actions
  901. #----------------------------------------------------------------------
  902. proc tixGrid:SetAnchor {w ent} {
  903.     if [string compare $ent ""] {
  904.     $w anchor set [lindex $ent 0] [lindex $ent 1]
  905. #    $w see $ent
  906.     }
  907. }
  908.  
  909. proc tixGrid:Select {w ent} {
  910.     $w selection clear
  911.     $w select set $ent
  912. }
  913.  
  914. proc tixGrid:StartScan {w} {
  915.     global tkPriv
  916.     set tkPriv(afterId) [after 50 tixGrid:AutoScan $w]
  917. }
  918.  
  919. proc tixGrid:DoScan {w} {
  920.     global tkPriv
  921.     set x $tkPriv(x)
  922.     set y $tkPriv(y)
  923.     set X $tkPriv(X)
  924.     set Y $tkPriv(Y)
  925.  
  926.     set out 0
  927.     if {$y >= [winfo height $w]} {
  928.     $w yview scroll 1 units
  929.     set out 1
  930.     }
  931.     if {$y < 0} {
  932.     $w yview scroll -1 units
  933.     set out 1
  934.     }
  935.     if {$x >= [winfo width $w]} {
  936.     $w xview scroll 2 units
  937.     set out 1
  938.     } 
  939.     if {$x < 0} {
  940.     $w xview scroll -2 units
  941.     set out 1
  942.     }
  943.  
  944.     if {$out} {
  945.     set tkPriv(afterId) [after 50 tixGrid:AutoScan $w]
  946.     }
  947. }
  948.  
  949. proc tixGrid:CallBrowseCmd {w ent} {
  950.     return
  951.  
  952.     set browsecmd [$w cget -browsecmd]
  953.     if {$browsecmd != ""} {
  954.     set bind(specs) {%V}
  955.     set bind(%V)    $ent
  956.  
  957.     tixEvalCmdBinding $w $browsecmd bind $ent
  958.     }
  959. }
  960.  
  961. proc tixGrid:CallCommand {w ent} {
  962.     set command [$w cget -command]
  963.     if {$command != ""} {
  964.     set bind(specs) {%V}
  965.     set bind(%V)    $ent
  966.  
  967.     tixEvalCmdBinding $w $command bind $ent
  968.     }
  969. }
  970.  
  971. # tixGrid:EditCell --
  972. #
  973. #    This command is called when "$w edit set $x $y" is called. It causes
  974. #    an SetEdit call when the grid's state is 0.
  975. #
  976. proc tixGrid:EditCell {w x y} {
  977.     set list $w:_list
  978.     global $list
  979.  
  980.     case [tixGrid:GetState $w] {
  981.     {0} {
  982.         tixGrid:SetEdit $w [list $x $y]
  983.            }
  984.     default {
  985.         lappend $list [list tixGrid:SetEdit $w [list $x $y]]
  986.     }
  987.     }
  988. }
  989.  
  990. # tixGrid:EditApply --
  991. #
  992. #    This command is called when "$w edit apply $x $y" is called. It causes
  993. #    an CheckEdit call when the grid's state is 0.
  994. #
  995. proc tixGrid:EditApply {w} {
  996.     set list $w:_list
  997.     global $list
  998.  
  999.     case [tixGrid:GetState $w] {
  1000.     {0} {
  1001.         tixGrid:CheckEdit $w
  1002.            }
  1003.     default {
  1004.         lappend $list [list tixGrid:CheckEdit $w]
  1005.     }
  1006.     }
  1007. }
  1008.  
  1009. # tixGrid:CheckEdit --
  1010. #
  1011. #    This procedure is called when the user sets the focus on a cell.
  1012. #    If another cell is being edited, apply the changes of that cell.
  1013. #
  1014. proc tixGrid:CheckEdit {w} {
  1015.     set edit $w.tixpriv__edit
  1016.     if [winfo exists $edit] {
  1017.     #
  1018.     # If it -command is not empty, it is being used for another cell.
  1019.     # Invoke it so that the other cell can be updated.
  1020.     #
  1021.     if ![tixStrEq [$edit cget -command] ""] {
  1022.         $edit invoke
  1023.     }
  1024.     }
  1025. }
  1026.  
  1027. # tixGrid:SetEdit --
  1028. #
  1029. #    Puts a floatentry on top of an editable entry.
  1030. #
  1031. proc tixGrid:SetEdit {w ent} {
  1032.     set edit $w.tixpriv__edit
  1033.     tixGrid:CheckEdit $w
  1034.  
  1035.     set editnotifycmd [$w cget -editnotifycmd]
  1036.     if [tixStrEq $editnotifycmd ""] {
  1037.     return
  1038.     }
  1039.     set px [lindex $ent 0]
  1040.     set py [lindex $ent 1]
  1041.  
  1042.     if ![uplevel #0 $editnotifycmd $px $py] {
  1043.     return
  1044.     }
  1045.     if [$w info exists $px $py] {
  1046.     if [catch {
  1047.         set oldValue [$w entrycget $px $py -text]
  1048.     }] {
  1049.         # The entry doesn't support -text option. Can't edit it.
  1050.         #
  1051.         # If the application wants to force editing of an entry, it could
  1052.         # delete or replace the entry in the editnotifyCmd procedure.
  1053.         #
  1054.         return
  1055.     }
  1056.     } else {
  1057.     set oldValue ""
  1058.     }
  1059.  
  1060.     set bbox [$w info bbox [lindex $ent 0] [lindex $ent 1]]
  1061.     set x [lindex $bbox 0]
  1062.     set y [lindex $bbox 1]
  1063.     set W [lindex $bbox 2]
  1064.     set H [lindex $bbox 3]
  1065.  
  1066.     if ![winfo exists $edit] {
  1067.     tixFloatEntry $edit
  1068.     }
  1069.  
  1070.     $edit config -command "tixGrid:DoneEdit $w $ent"
  1071.     $edit post $x $y $W $H
  1072.  
  1073.     $edit config -value $oldValue
  1074. }
  1075.  
  1076. proc tixGrid:DoneEdit {w x y args} {
  1077.     set edit $w.tixpriv__edit
  1078.     $edit config -command ""
  1079.     $edit unpost
  1080.  
  1081.     set value [tixEvent value]
  1082.     if [$w info exists $x $y] {
  1083.     if [catch {
  1084.         $w entryconfig $x $y -text $value
  1085.     }] {
  1086.         return
  1087.     }
  1088.     } elseif ![tixStrEq $value ""] {    
  1089.     if [catch {
  1090.         # This needs to be catch'ed because the default itemtype may
  1091.         # not support the -text option
  1092.         #
  1093.         $w set $x $y -text $value
  1094.     }] {
  1095.         return
  1096.     }
  1097.     } else {
  1098.     return
  1099.     }
  1100.  
  1101.     set editDoneCmd [$w cget -editdonecmd]
  1102.     if ![tixStrEq $editDoneCmd ""] {
  1103.     uplevel #0 $editDoneCmd $x $y
  1104.     }
  1105. }
  1106.  
  1107. proc tixGrid:SetFocus {w} {
  1108.     if [$w cget -takefocus] {
  1109.     if ![string match $w.* [focus -displayof $w]] {
  1110.         focus $w
  1111.     }
  1112.     }
  1113. }
  1114.